#pragma once

#include <string>
#include <vector>

#include "X509Certificate.h"
#include "PKCS8Certificate.h"
#include "PublicKey.h"
#include "KeyInfo.h"

#include <QScopedPointer>

namespace kryptos { namespace cryptography {

class KeyManager
{
public:

    virtual ~KeyManager();

    static KeyManager& instance();

    int createAndStoreKey      (kryptos::entities::KeyInfo &info);
    int addPublicKey           (const std::string& publicKeyFile);
    int addPrivateKey          (const std::string& privateKeyFile);

    kryptos::entities::KeyInfo     keyInfo        (const std::string& id);
    kryptos::entities::KeyInfoList allKeys        ();
    kryptos::entities::KeyInfoList indentities    ();
    kryptos::entities::KeyInfoList searchKeyInfo  (const std::string& query);

    bool hasKeyWithNameAndEmail(const std::string &name, const std::string& email);
    bool hasKeyWithEmail       (const std::string& email);
    bool hasKeyWithId          (const std::string& id);

    PrivateKey findKey         (const std::string& idOrEmail, const std::string& userPassphrase);
    PublicKey  findPublicKey   (const std::string& idOrEmail);

    X509Certificate  generatePublicKeyCert(const std::string& idOrEmail, const std::string& userPassphrase);

protected:

    KeyManager();

private:
    Q_DISABLE_COPY(KeyManager)
};

}}
